package edu.cuit.svsp.controller;

import edu.cuit.svsp.request.ResponseResult;
import edu.cuit.svsp.service.CollectService;
import edu.cuit.svsp.util.JWTUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @className: CollectController
 * @author: pjy
 * @description: 收藏控制器
 * @date: 2024/7/7
 */
@RestController
@RequestMapping("/collect")
public class CollectController {
    @Resource
    private CollectService collectService;

    // 更新收藏
    @GetMapping("/update/{isLike}/{vid}")
    public ResponseResult updateCollect(@PathVariable("isLike") boolean isLike, @PathVariable("vid") Integer vid, HttpServletRequest request){
        int uid = JWTUtil.getuid(request.getHeader("Authorization"));
        return new ResponseResult(HttpStatus.OK.value(), "success", collectService.updateCollect(isLike, vid, uid));
    }
    // 查收藏
    @GetMapping("/findCollect/{vid}")
    public ResponseResult findCollect(@PathVariable("vid") Integer vid, HttpServletRequest request){
        int uid = JWTUtil.getuid(request.getHeader("Authorization"));
        boolean collect = collectService.findCollect(vid, uid);
        return new ResponseResult(HttpStatus.OK.value(), "success", collect);
    }
}
